﻿<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .wrap {
            width: 400px;
            height: 400px;
            margin: 100px auto 0;
        }

        .wrap h1 {
            text-align: center;
        }

        .wrap div {
            width: 400px;
            height: 300px;
            background: pink;
            font-size: 30px;
            text-align: center;
            line-height: 300px;
        }
    </style>
    <script src="./jquery-1.11.1.js"></script>
    <script>
        $(function(){
            $(document).on('keydown',function(e){
                // 65: a  66:b ....
                if(e.keyCode == 65){
                    $('#bgChange').css('backgroundColor','red')
                    $('#keyCodeSpan').text(e.keyCode)
                }
                else if(e.keyCode == 66){
                    $('#bgChange').css('backgroundColor','yellow')
                    $('#keyCodeSpan').text(e.keyCode)
                }
            })
        })
    </script>
</head>
<body>

    <div class="wrap">
        <h1>按键改变颜色</h1>
        <div id="bgChange">
            keyCode为：
            <span id="keyCodeSpan"></span>
        </div>
    </div>

</body>
</html>
